package cn.schtwz.baseproject.di

import cn.schtwz.baselib.http.CustomGsonConverterFactory
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.dsl.module
import retrofit2.Retrofit
import java.util.concurrent.TimeUnit

const val BASE_URL = "https://wanandroid.com/"
const val TIME_OUT_SECONDS = 10
val httpClientModule = module {

    single<Retrofit> {
        Retrofit.Builder()
            .baseUrl(BASE_URL)
            .client(get())
            .addConverterFactory(CustomGsonConverterFactory.create())
            .build()

    }
    single<OkHttpClient> {
        OkHttpClient.Builder()
            .connectTimeout(
                TIME_OUT_SECONDS.toLong(),
                TimeUnit.SECONDS
            )
            .readTimeout(
                TIME_OUT_SECONDS.toLong(),
                TimeUnit.SECONDS
            )
            .addInterceptor(
                HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
            )
//            .addInterceptor(
//                BasicParamsInterceptor.Builder()
//                    .addHeaderParam("token", RxSPTool.getString(MyApplication.INSTANCE, Const.SP_TOKEN))
//                    .build()
//
//            )
            .build()
    }

}
